#include <iostream>
#include <string>
#include <jsoncpp/json/json.h>

typedef struct Request
{
    int _x;
    int _y;
    char _op;   // "+-*/%"
}request_t;

int main()
{
    std::string json_string = R"({"datax" : 10, "datay": 20, "operator" : 42 })"; 
    // std::cout << json_string << std::endl;

    Json::Reader reader;
    Json::Value root;

    reader.parse(json_string, root);
    request_t req;
    req._x = root["datax"].asInt();
    req._y = root["datay"].asInt();
    req._op = (char)root["operator"].asUInt();

    std::cout << req._x << " " << req._op << " " << req._y << std::endl;
    // 序列化的过程
    // request_t req = { 10, 20, '+' };

    // Json::Value root;
    // root["datax"] = req._x;
    // root["datay"] = req._y;
    // root["operator"] = req._op;

    // //Json::StyledWriter writer;
    // Json::FastWriter writer;
    // std::string json_string = writer.write(root);
    // std::cout << json_string << std::endl;

    return 0;
}